﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Atomic.Common;
using Atomic.Common.Validators;
using Atomic.FriendLinks.DAL;

namespace Atomic.FriendLinks.BLL
{
    /// <summary>
    /// 友情链接业务实现
    /// </summary>
    public class LinkBLL : ErrorImpl, ILink
    {
        #region ILink 成员

        /// <summary>
        /// 添加新的友情链接
        /// </summary>
        /// <param name="entity">友情链接信息</param>
        /// <returns>是否添加成功</returns>
        public virtual bool Add(Entities.LinkEntity entity)
        {
            //实体输入验证
            if (!(VResult = entity.Validate()).Success)
            {
                Error = new ErrorResult()
                {
                    Message = VResult.FailureMessage
                };
                return false;
            }

            //保存链接
            LinkDAL linkDAL = new LinkDAL();
            linkDAL.Add(entity);
            return true;
        }

        /// <summary>
        /// 删除指定链接
        /// </summary>
        /// <param name="id">链接ID</param>
        /// <returns>是否删除成功</returns>
        public virtual bool Remove(int id)
        {
            LinkDAL linkDAL = new LinkDAL();
            linkDAL.Remove(id);
            return true;
        }

        /// <summary>
        /// 更新友情链接信息
        /// </summary>
        /// <param name="entity">新友情链接信息</param>
        /// <param name="id">要更新的友情链接ID</param>
        /// <returns>是否更新成功</returns>
        public virtual bool Update(Entities.LinkEntity entity, int id)
        {
            //实体输入验证
            if (!(VResult = entity.Validate()).Success)
            {
                Error = new ErrorResult()
                {
                    Message = VResult.FailureMessage
                };
                return false;
            }

            //保存链接
            LinkDAL linkDAL = new LinkDAL();
            linkDAL.Update(entity, id);
            return true;
        }

        /// <summary>
        /// 获取指定ID的友情链接信息
        /// </summary>
        /// <param name="id">友情链接ID</param>
        /// <returns>友情链接信息</returns>
        public virtual Entities.LinkEntity Get(int id)
        {
            LinkDAL linkDAL = new LinkDAL();
            return linkDAL.Get(id);
        }

        /// <summary>
        /// 获取所有友情链接
        /// </summary>
        /// <returns>友情链接</returns>
        public virtual List<Entities.LinkEntity> GetList()
        {
            LinkDAL linkDAL = new LinkDAL();
            return linkDAL.GetList();
        }

        #endregion
    }
}
